﻿
var hdnCheckvalidationAdsl = $("#hdnCheckvalidationAdsl").val();
var hdnCheckvalidationUsername = $("#hdnCheckvalidationUsername").val();

var signUp = "signUp";

var hdnTick = $("#hdnTick").val();
var hdnCross = $("#hdnCross").val();


$(function () {
    $("#accordion").accordion();
    $('.checkvalidationtitle, .checkvalidationstring, .checkvalidationinteger, .checkvalidationAddress, .checkvalidationemail').next().html('<img src=' + $("#hdnTick").val() + ' />');

    //on Page Load Add this class to check blank values and open this panel on submit.

    if ($("#UserName").val() != '') {
        $("#UserName").removeClass("errorforaccordian");
    }
    else {
        $("#UserName").addClass("errorforaccordian");
    }
    if ($("#ADSLprovider").val() != '') {
        $("#ADSLprovider").removeClass("errorforaccordian");
    }
    else {
        $("#ADSLprovider").addClass("errorforaccordian");
    }

    var getfirstRadio = $(".rdselect").val();
    var getselectRadio = $(".rdselect:checked").val();

    //first time bind check
    if (getselectRadio == '') {
        $("#PlanNamesDetailID").val(getfirstRadio);

    }
    //value is in database check
    else {
        $("#PlanNamesDetailID").val(getselectRadio);

        //check the cookie values(if user already selected the plan and quota)
        // 1.) Main Plans:
        var chkSplit = $.cookie("PlanCookie");
        if (chkSplit != null) {
            var ckPlanNamesDetailID = $.cookie("PlanCookie").split('|')[0];
        }
        if (ckPlanNamesDetailID != null) {
            $(".rdselect").each(function (index) {

                if ($(this).val() == ckPlanNamesDetailID) {
                    $(this).attr('checked', 'checked');
                }

            });
            $("#PlanNamesDetailID").val(ckPlanNamesDetailID);
        }
    }



    var getfirstRadioContract = $(".rdselectcontract").val();
    var getselectcontract = $(".rdselectcontract:checked").val();

    //first time bind check
    if (getselectcontract == '') {
        $("#PlanQuotaID").val(getfirstRadioContract);
    }
    //value is in database check
    else {
        $("#PlanQuotaID").val(getselectcontract);

        //check the cookie values(if user already selected the plan and quota)
        //2.) Main Quota:
        var chkSplit = $.cookie("PlanCookie");

        if (chkSplit != null) {
            var ckPlanQuotaID = $.cookie("PlanCookie").split('|')[1];
        }
        if (ckPlanQuotaID != null) {
            $(".rdselectcontract").each(function (index) {

                if ($(this).val() == ckPlanQuotaID) {
                    $(this).attr('checked', 'checked');
                }

            });
            $("#PlanQuotaID").val(ckPlanQuotaID);
        }
    }


});

//on click of submit open that panel that is not filled.
$('#btnNextSubmit').live('click', function () {
    var index = parseInt($(".errorforaccordian").closest(".ui-accordion-content").index());
    if (index == 5) {

        $("#accordion").accordion("activate", 2);
    }
    else if (index == 1) {
        $("#accordion").accordion("activate", 0);
    }

    else if (index == 9) {
        $("#accordion").accordion("activate", 4);
    }
    else if (index == 13) {
        $("#accordion").accordion("activate", 6);
    }
    else if (index == 17) {
        $("#accordion").accordion("activate", 8);
    }
    else if (index == 21) {
        $("#accordion").accordion("activate", 10);
    }
    else if (index == 25) {
        $("#accordion").accordion("activate", 12);
    }
    else if (index == 29) {
        $("#accordion").accordion("activate", 14);
    }
    else if (index == 33) {
        $("#accordion").accordion("activate", 16);
    }
    else if (index == 37) {
        $("#accordion").accordion("activate", 18);
    }
    else if (index == 41) {
        $("#accordion").accordion("activate", 20);
    }
});

$('#aMoveNext').live('click', function () {
    $("#accordion").accordion("activate", 2);
    });
$('#aMoveNextmain').live('click', function () {
    $("#accordion").accordion("activate", 4);
});

$('.adynamicNext').live('click', function () {
    var getclickid = $(this).attr('id').split('_')[1];
    if (getclickid == 1) {
        $("#accordion").accordion("activate", 6);
    }
    else if (getclickid == 2) {
        $("#accordion").accordion("activate", 8);
    }
    else if (getclickid == 3) {
        $("#accordion").accordion("activate", 10);
    }
    else if (getclickid == 4) {
        $("#accordion").accordion("activate", 12);
    }
    else if (getclickid == 5) {
        $("#accordion").accordion("activate", 14);
    }
    else if (getclickid == 6) {
        $("#accordion").accordion("activate", 16);
    }
    else if (getclickid == 7) {
        $("#accordion").accordion("activate", 18);
    }
    else if (getclickid == 8) {
        $("#accordion").accordion("activate", 20);
    }
});


$('.checkvalidationAdsl').live('blur', function () {
    var getValue = '';
    getValue = $(this).val();
    getthis = $(this);

    if (getValue != '') {
        $(this).removeClass("errorforaccordian");
        $('#loadingmessage').show();
        $.ajax({
            type: "GET",
            data: { matchValue: getValue },
            url: hdnCheckvalidationAdsl,
            success: function (msg) {
                if (msg == 1) {

                    getthis.next().html('<img src=' + hdnTick + ' />');
                    $('#loadingmessage').hide();
                }
                else {
                    getthis.next().html('<img src=' + hdnCross + ' />');
                    $('#loadingmessage').hide();
                }
            }
        });
    }
    else {
        $(this).addClass("errorforaccordian");
        getthis.next().html('');
        $('#loadingmessage').hide();
    }
});

$('.checkvalidationUsername').live('blur', function () {
    var getValue = '';
    getValue = $(this).val();
    getthis = $(this);

    if (getValue != '') {
        $(this).removeClass("errorforaccordian");
        $('#loadingmessage').show();
        $.ajax({
            type: "GET",
            data: { matchValue: getValue },
            url: hdnCheckvalidationUsername,
            success: function (msg) {
                if (msg == 1) {

                    getthis.next().html('<img src=' + hdnTick + ' />');
                    $('#loadingmessage').hide();
                }
                else {
                    getthis.next().html('<img src=' + hdnCross + ' />');
                    $('#loadingmessage').hide();
                }
            }
        });
    }
    else {
        $(this).addClass("errorforaccordian");
        getthis.next().html('');
        $('#loadingmessage').hide();
    }
});

$("#SelectedTitleItem").live("change", function (e) {
    $("#Title").val($("#SelectedTitleItem").val());
});

$(".rdselect").live("change", function (e) {
    $("#PlanNamesDetailID").val($(this).val());
});
$(".rdselectcontract").live("change", function (e) {
    $("#PlanQuotaID").val($(this).val());
});

